package com.java.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java.admin.mapper.AdminUserMapper;
import com.java.admin.service.UserService;
import com.java.clients.UserClient;
import com.java.param.CartListParam;
import com.java.param.PageParam;
import com.java.pojo.User;
import com.java.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.crypto.tls.UserMappingType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserClient userClient;
    /**
     * 根据分页数据调用feign客户端，获取用户信息
     *
     * @param pageParam
     * @return
     */
    //添加缓存
    @Cacheable(value = "list.user",key = "#pageParam.currentPage+'-'+#pageParam.pageSize")
    @Override
    public R list(PageParam pageParam) {
        R r = userClient.listPage(pageParam);
        log.info("AdminUserServiceImpl.list 业务已经完成,结果:{}", r);
        return r;
    }

    @CacheEvict(value = "list.user",allEntries = true)
    @Override
    public R remove(CartListParam cartListParam) {
        R r = userClient.userRemove(cartListParam);
        log.info("UserServiceImpl.remove 业务已经完成,结果:{}", r);
        return r;
    }

    @CacheEvict(value = "list.user",allEntries = true)
    @Override
    public R update(User user) {
        R r = userClient.update(user);
        log.info("UserServiceImpl.update 业务已经完成,结果:{}", r);
        return r;
    }

    @CacheEvict(value = "list.user",allEntries = true)
    @Override
    public R save(User user) {
        R r = userClient.save(user);
        log.info("UserServiceImpl.save 业务已经完成,结果:{}", r);
        return r;
    }
}
